package com.gdufe.firesafe.interceptor;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//拦截指定的请求路径，注册拦截器
//SpringBoot拦截器SpringBoot拦截器继承WebMvcConfigurationSupport导致date-format时间格式失效
//解决办法：不继承WebMvcConfigurationSupport，修改为实现WebMvcConfigurer接口
@Configuration
public class UserInterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry){
        registry.addInterceptor(jwtUserInterceptor())  //配置jwt拦截器规则
                .addPathPatterns("/**")  //拦截所有的请求路径
                .excludePathPatterns("/login","/register");  //除了登录，注册请求
    }

    @Bean
    public JWTUserInterceptor jwtUserInterceptor(){
        return new JWTUserInterceptor();
    }
}
